package com.kelvin.paopao.module.chat.friend;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.kelvin.paopao.R;
import com.kelvin.paopao.adapter.FriendAdapter;
import com.kelvin.paopao.api.responseBean.DatePersonModel;
import com.kelvin.paopao.injector.components.DaggerFriendComponent;
import com.kelvin.paopao.injector.modules.FriendModule;
import com.kelvin.paopao.module.base.BaseActivity;
import com.kelvin.paopao.module.base.IBasePresenter;
import com.kelvin.paopao.module.chat.message.MessageActivity;
import com.kelvin.paopao.module.person.detail.PersonDetailActivity;
import com.kelvin.paopao.widgets.CustomToolbar;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by Administrator on 2017/5/10.
 */

public class FriendActivity extends BaseActivity<IBasePresenter> implements IFriendView {
    @BindView(R.id.custom_toolbar)
    CustomToolbar customToolbar;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    @Inject
    FriendAdapter adapter;

    private LinearLayoutManager manager;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_friend;
    }

    @Override
    protected void initInjector() {
        DaggerFriendComponent.builder().friendModule(new FriendModule(this)).build()
                .inject(this);
    }

    @Override
    protected void initViews() {
        customToolbar.showBackIcon(this);
        manager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                PersonDetailActivity.launch(FriendActivity.this,((DatePersonModel)adapter.
                        getData().get(position)).getUser_no());
            }
        });
    }

    @Override
    protected void updateViews(boolean isRefresh) {
        mPresenter.getData(isRefresh);
    }

    public static void launch(Context context) {
        Intent intent = new Intent(context, FriendActivity.class);
        context.startActivity(intent);
    }

    @Override
    public void loadData(List<DatePersonModel> models) {
        adapter.setNewData(models);
    }

    @Override
    public void showNoData() {
        View nodataView = LayoutInflater.from(this).inflate(R.layout.view_no_data,
                (ViewGroup) recyclerView.getParent(), false);
        adapter.setEmptyView(nodataView);
    }
}
